package com.qingke.oms.command.user;

import java.util.List;

import com.qingke.oms.app.OrderManagementSystemAppliction;
import com.qingke.oms.command.Command;
import com.qingke.oms.command.UserCommand;
import com.qingke.oms.pojo.Shop;
import com.qingke.oms.pojo.User;
import com.qingke.oms.util.OMSConsole;

public class GoToShopCommand extends UserCommand {

	public GoToShopCommand(User user) {
		super(user);
	}

	@Override
	public void execute() {
		List<Shop> list=dao.selectAllShop();
		if(list.size()==0){
			OMSConsole.println("There is no shop now.");
			return ;
		}
		Command command = new ListAllShopCommand(user);
		command.execute();
		String shopIdStr;
		while(true){
			shopIdStr=OMSConsole.promptNotEmpty("shop id:").trim();
			if(!shopIdStr.replaceAll("[0-9]","").equals("")){
				OMSConsole.println("err input.");
				continue;
			}
			break;
		}
		int shopIdInt=Integer.parseInt(shopIdStr);
		
		Shop shop = dao.selectShopById(shopIdInt);
		if(shop==null)
			OMSConsole.println("The shop is not existed.");
		else{
			OMSConsole.println("welcome to "+shop.getName());
			OMSConsole.println("you can input help command for help.");
			OrderManagementSystemAppliction.getInstance().setShop(shop);
		}
	}

}
